<template>
  
</template>
<script setup>
    import {computed, onMounted,onBeforeUnmount, ref,defineEmits} from 'vue';
	import { GetOrderCalcInfo,ApiGetCurrentOrder} from '../api/order';
	import { useStore } from "vuex";
	
	const $store = useStore();
	const $emits = defineEmits(['receiveMsg']);
	let timer = null;
	//let url = ref(`/static/sseMessage.html`);
	
	  /**
	   * onMounted(()=>{
		if(window){
			window.addEventListener("message", handleMessage, false);
		}
	})
	   */
	onMounted(()=>{
		calcTimer();
	    
	})
	onBeforeUnmount(()=>{
		if(timer){
			clearInterval(timer);
		}
	    
	})
	
	const calcTimer = () =>{
	   timer = setInterval(()=>{
	        getOrderCalc();
	    }, 3000)
	}
	
	const getOrderCalc =async () => {
		const { error, result } = await ApiGetCurrentOrder();
		//const { error, result } = await GetOrderCalcInfo({orderNo: $store.state.orderNo});
		if (result) {
		   $emits('receiveMsg', result)
		   
		   if(result.cancel){
			   clearInterval(timer);
		   }
		}
	    
	}
</script>